<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Theme Clock</title>
    <script>
        window.onload = function(){
            const hourE1 = document.querySelector('.hour')
            const minuteE1 = document.querySelector('.minute')
            const secondE1 = document.querySelector('.second')
            const timeE1 = document.querySelector('.time')
            const dateE1 = document.querySelector('.date')
            const toggle = document.querySelector('.toggle')


            const days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
            const months = ['Jan','Fab','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']

            toggle.addEventListener('click',e=>{
                const html = document.querySelector('html')
                if(html.classList.contains('dark')){
                    html.classList.remove('dark')
                    e.target.innerHTML = 'Dark mode'
                }else{
                    html.classList.add('dark')
                    e.target.innerHTML = 'Light mode'
                }
            })

            function setTime(){
                const time = new Date()
                const month = time.getMonth()
                const day = time.getDay()
                const date = time.getDate()
                const hours = time.getHours()
                const hoursForClock = hours>=13?hours%12:hours;
                const minutes = time.getMinutes()
                const seconds = time.getSeconds()
                const ampm = hours >= 12?'PM':'AM'

                hourE1.style.transform = `translate(-50%,-100%) rotate(${scale(hoursForClock,12)}deg)`
                minuteE1.style.transform = `translate(-50%,-100%) rotate(${scale(minutes,60)}deg)`
                secondE1.style.transform = `translate(-50%,-100%) rotate(${scale(seconds,60)}deg)`

                timeE1.innerHTML = `${hoursForClock}:${minutes < 10 ? `0${minutes}`: minutes} ${ampm}`
                dateE1.innerHTML = `${days[day]},${months[month]} <span class="circle">${date}</span>`

            }

            const scale = (num,deg) => num*360/deg
            

            setTime()

            setInterval(setTime,1000)
        }
    </script>
    <style>
        *{
            box-sizing: border-box;
        }
        :root{
            --primary-color:#000;
            --secondary:#fff;
        }

        html{
            transition: all 0.5s ease-in;
        }

        html.dark{
            --primary-color:#fff;
            --secondary:#000;
        }
        html.dark{
            background-color: #111;
            color: var(--primary-color);
        }

        body{
            font-family: 'Heebo' sans-serif;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            overflow: hidden;
            margin: 0;
        }

        .toggle{
            cursor: pointer;
            background-color: var(--primary-color);
            color: var(--secondary);
            border: 0;
            border-radius: 4px;
            padding: 8px 12px;
            position: absolute;
            top: 100px;
        }

        .toggle:focus{
            outline: none;
        }


        .clock{
            position: relative;
            width: 200px;
            height: 200px;
            
        }

        .needle{
            background-color: var(--primary-color);
            position: absolute;
            top: 50%;
            left: 50%;
            height: 65px;
            width: 3px;
            transform-origin: bottom center;
            transition: all 0.5s ease-in;
        }

        .needle.hour{
            transform: translate(-50%,-100%) rotate(0deg);
        }
        .needle.minute{
            transform: translate(-50%,-100%) rotate(0deg);
            height: 100px;
        }
        .needle.second{
            transform: translate(-50%,-100%) rotate(0deg);
            height: 100px;
            background-color: #E74c3c;
        }
        .center-point{
            background-color: #e74c3c;
            width: 10px;
            height: 10px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            border-radius: 50%;
        }
        .center-point::after{
            content: '';
            background-color: var(--primary-color);
            width: 5px;
            height: 5px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            border-radius: 50%;
        }

        .time{
            font-size: 60px;
        }

        .date{
            color: #aaa;
            font-size: 14px;
            letter-spacing: 0.3px;
            text-transform: uppercase;
            text-align: center;
        }
        .date .circle{
            background-color: var(--primary-color);
            color: var(--secondary);
            border-radius: 50%;
            height: 18px;
            width: 18px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            line-height: 18px;
            transition: all 0.5s ease-in;
            font-size: 12px;
        }
    </style>
</head>
<body>
    <button class="toggle">Dark mode</button>

    <div class="clock-container">
        <div class="clock">
            <div class="needle hour"></div>
            <div class="needle minute"></div>
            <div class="needle second"></div>
            <div class="center-point"></div>
        </div>

        <div class="time"></div>
        <div class="date"></div>
    </div>
</body>
</html>